import java.util.Arrays;

class Student{
    protected String name;
    protected int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class Test {

    public static void main(String[] args) {
        String str1 = "SncanaHNd";
        String str2 = "snCanaHnD";
        //charAt:字符串中某字符的下标
        char ch = str1.charAt(3);
        System.out.println(ch);

        //indexOf:字符串中某下标的字符
        int a = str2.indexOf('D');
        System.out.println(a);

    }

    //字符串的截取：
    public static void main11(String[] args) {
        String str = "abcdefg";
        String ret = str.substring(4);
        String ret2 = str.substring(2,4);

        System.out.println(ret);
        System.out.println(ret2);
    }

    //字符串拆分：
    public static void main10(String[] args) {
        String str = "name=lihaoyang=haha=250";
        String [] ch = str.split("=",3);
        System.out.println(Arrays.toString(ch));
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);
        }

        String str2 = "2022.07.01.11.24";
        String [] ret2 = str2.split("\\.",2);
        System.out.println(Arrays.toString(ret2));
        for (int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }

////        多次分割：
//        String str3 = "name=lihaoyang@haha&250";
//        String [] ret3 = str3.split("=|&|@");
//        System.out.println(Arrays.toString(ret3));
//        for (int i = 0; i < ret3.length; i++) {
//            System.out.println(ret3[i]);
//        }

        String str3 = "name=lihaoyang&haha=250";
        String [] ret3 = str3.split("&");
        for (String x:ret3) {
            String [] ss = x.split("=");
            for (String xx: ss) {
                System.out.println(xx);
            }
        }
    }

    //字符串的替换：
    public static void main9(String[] args) {
        String str = "abababaabcasdacascvb";
        String ret1 = str.replace('a','k');//replaceAll
        String ret2 = str.replace("ab","sss");

        String ret3 = str.replaceFirst("ab","sss");

        System.out.println(str);
        System.out.println(ret1);
        System.out.println(ret2);
        System.out.println(ret3);

    }

    //字符串转数组：
    public static void main8(String[] args) {
        String str = "abcdef";
        char [] ch = str.toCharArray();
        System.out.println(Arrays.toString(ch));

        //格式化输出：
        String ret = String.format("%d-%d-%d",2024,12,24);
        System.out.println(ret);

    }

    public static void main7(String[] args) {
        String str = "AbCdE";

        //并不是在原字符串本身上进行修改
        String ret1 = str.toUpperCase();
        String ret2 = str.toLowerCase();
        System.out.println(str);
        System.out.println(ret1);
        System.out.println(ret2);

    }


    public static void main6(String[] args) {
        String str1 = String.valueOf(123);
        String str2 = String.valueOf(123.4);
        System.out.println(str1);
        System.out.println(str2);
        String str3 = String.valueOf(new Student("Jim",10));
        System.out.println(str3);

        int a = Integer.parseInt("12345");
        System.out.println(a + 1);
    }

    public static void main5(String[] args) {
        String str1 = "abcsjaabcabcacbskjk";
        int index = str1.lastIndexOf("abc");
        System.out.println(index);
    }

    public static void main4(String[] args) {
        String str1 = "SncanaHNd";
        String str2 = "snCanaHnD";
        //charAt:字符串中某字符的下标
        char ch = str1.charAt(3);
        System.out.println(ch);

        //indexOf:字符串中某下标的字符
        int a = str2.indexOf('D');
        System.out.println(a);
    }

    public static void main3(String[] args) {
        String str1 = "SncanaHNd";
        String str2 = "snCanaHnD";
        System.out.println(str1.equalsIgnoreCase(str2));
        System.out.println(str1.compareTo(str2));
        System.out.println(str1.compareToIgnoreCase(str2));
    }

    public static void main2(String[] args) {
        String s = "abcbca";
        System.out.println(s.length());
        System.out.println(s.isEmpty());

        String s2 = "";
        System.out.println(s2.length());
        System.out.println(s2.isEmpty());
    }

    public static void main1(String[] args) {
        String str1 = "abcdefg";
        System.out.println(str1);

        String str2 = new String("yyxzz");
        System.out.println(str2);

        int [] array1 = {1,2,3,4,5};
        System.out.println(Arrays.toString(array1));

        int [] array2 = new int[] {6,7,8,9,10};
        System.out.println(Arrays.toString(array2));

        char [] value = {'J','i','m'};
        String str = new String(value);
        System.out.println(value);
    }
}
